package com.glowworms.core.web.bind;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebArgumentResolver;
import org.springframework.web.context.request.NativeWebRequest;

/**
 * 	用于注解控制器的方法参数解析注入
 */
public class ControllerMethodArgumentResolver implements WebArgumentResolver {

	/**
	 * 
	 */
	public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception {
		
		//核心方法参数
		if(methodParameter.getParameterType().equals(RequestAndResponse.class)){
			return new RequestAndResponse((HttpServletRequest)webRequest.getNativeRequest(), (HttpServletResponse)webRequest.getNativeResponse());
		}
		return null;
	}

}
